# 员工管理API日期格式修复测试脚本

Write-Host "=== 员工管理API日期格式修复测试 ===" -ForegroundColor Green

# 等待应用程序启动
Write-Host "等待应用程序启动..." -ForegroundColor Yellow
Start-Sleep -Seconds 10

# 测试1: 修改员工（包含多种日期格式）
Write-Host "`n测试1: 修改员工（包含多种日期格式）" -ForegroundColor Cyan

$updateEmpData = @{
    id = 4
    username = "zhangwuji"
    password = "123456"
    name = "张无忌"
    gender = 1
    image = "https://web-framework.oss-cn-hangzhou.aliyuncs.com/2022-09-02-00-27-53B.jpg"
    position = 2
    salary = 8000
    hireDate = "2015-01-01"
    deptId = 2
    createTime = "2022-09-01T23:06:30"
    updateTime = "2022-09-02T00:29:04"
    exprList = @(
        @{
            startDate = "2012-07-01"
            endDate = "2015-06-20"
            company = "中软国际股份有限公司"
            position = "java开发"
        },
        @{
            startDate = "2015-07-01"
            endDate = "2019-03-03"
            company = "百度科技股份有限公司"
            position = "java开发"
        },
        @{
            startDate = "2019-3-15"
            endDate = "2023-03-01"
            company = "阿里巴巴科技股份有限公司"
            position = "架构师"
        }
    )
} | ConvertTo-Json -Depth 10

Write-Host "发送修改员工请求..." -ForegroundColor Yellow
Write-Host "请求数据: $updateEmpData" -ForegroundColor Gray

try {
    $response = Invoke-WebRequest -Uri "http://localhost:8080/emps" -Method PUT -Body $updateEmpData -ContentType "application/json"
    Write-Host "修改员工成功!" -ForegroundColor Green
    Write-Host "响应状态: $($response.StatusCode)" -ForegroundColor Green
    Write-Host "响应内容: $($response.Content)" -ForegroundColor Green
} catch {
    Write-Host "修改员工失败!" -ForegroundColor Red
    Write-Host "错误信息: $($_.Exception.Message)" -ForegroundColor Red
}

# 测试2: 查询修改后的员工
Write-Host "`n测试2: 查询修改后的员工" -ForegroundColor Cyan

try {
    $response = Invoke-WebRequest -Uri "http://localhost:8080/emps/4" -Method GET
    Write-Host "查询员工成功!" -ForegroundColor Green
    Write-Host "响应状态: $($response.StatusCode)" -ForegroundColor Green
    Write-Host "响应内容: $($response.Content)" -ForegroundColor Green
} catch {
    Write-Host "查询员工失败!" -ForegroundColor Red
    Write-Host "错误信息: $($_.Exception.Message)" -ForegroundColor Red
}

# 测试3: 添加新员工（测试不同日期格式）
Write-Host "`n测试3: 添加新员工（测试不同日期格式）" -ForegroundColor Cyan

$newEmpData = @{
    username = "testuser"
    password = "123456"
    name = "测试用户"
    gender = 1
    phone = "13800138000"
    position = 1
    salary = 6000
    hireDate = "2020-5-15"
    deptId = 1
    exprList = @(
        @{
            startDate = "2018/06/01"
            endDate = "2020/05/01"
            company = "测试公司"
            position = "测试职位"
        }
    )
} | ConvertTo-Json -Depth 10

Write-Host "发送添加员工请求..." -ForegroundColor Yellow
Write-Host "请求数据: $newEmpData" -ForegroundColor Gray

try {
    $response = Invoke-WebRequest -Uri "http://localhost:8080/emps" -Method POST -Body $newEmpData -ContentType "application/json"
    Write-Host "添加员工成功!" -ForegroundColor Green
    Write-Host "响应状态: $($response.StatusCode)" -ForegroundColor Green
    Write-Host "响应内容: $($response.Content)" -ForegroundColor Green
} catch {
    Write-Host "添加员工失败!" -ForegroundColor Red
    Write-Host "错误信息: $($_.Exception.Message)" -ForegroundColor Red
}

Write-Host "`n=== 测试完成 ===" -ForegroundColor Green
